﻿using System.Collections.Generic;

using System.Net.DnsToolkit.Packet;

namespace System.Net.DnsToolkit.Serializer.Stream.Reader {
    public class RecordReaderProvider : IRecordReaderProvider<System.IO.Stream> {

        private readonly IDictionary<QTypeEnum, IRecordReader<System.IO.Stream>> _recordIndex;

        public RecordReaderProvider(params IRecordReader<System.IO.Stream>[] recordReaders) {
            _recordIndex = new Dictionary<QTypeEnum, IRecordReader<System.IO.Stream>>();
            Array.ForEach(recordReaders, r => _recordIndex.Add(r.QTypeEnum, r));
        }

        public IRecordReader<System.IO.Stream> Provide(QTypeEnum qTypeEnum) {

            if (!_recordIndex.ContainsKey(qTypeEnum)) {
                throw new NotImplementedException(string.Format("QTypeEnum.{0}", qTypeEnum));
            }

            return _recordIndex[qTypeEnum];
        }

    }
}
